/**
 * PHOSIDE: PHosphorylation Site IDentification Engine.
 * Copyright 2009 Digital Biology Lab, University of Missouri.
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 3 of the License, or (at your option) any later
 * version. <p/> This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more
 * details.
 */

package phoside.data.nr;

import java.util.List;

import phoside.Protein;
import phoside.Proteins;
import phoside.ProteinsImpl;


/**
 *
 * @author gjj
 */
public class ProteinNRBuilderImpl implements ProteinNRBuilder {
    protected final ProteinCluster cluster;
    protected final ProteinSelector selector;

    public ProteinNRBuilderImpl(final ProteinCluster cluster) {
        this (cluster, new ProteinSelectorPhosphoPreferred());
    }

    public ProteinNRBuilderImpl(final ProteinCluster cluster,
            final ProteinSelector selector) {
        this.cluster = cluster;
        this.selector = selector;
    }

    /**
     * {@inheritDoc}
     */
    public Proteins build(Proteins proteins) throws Exception {
        List<List<Protein>> clust = cluster.build(proteins);
        Proteins nrProteins = new ProteinsImpl();

        if (clust==null) {
            return null;
        }

        for (List<Protein> pros : clust) {
            nrProteins.addProtein(selector.select(pros));
        }

        return nrProteins;
    }
}
